<?php
/**
 * 网站首页
 */
class IndexController extends AppController {
	
	/**
	 * 初始化执行
	 *
	 * @see AppController::beforeFilter()
	 */
	public function beforeFilter() {
		parent::beforeFilter ();
	}
	public function index() {
		$this->set ( 'title_for_layout', '女人集市 - 爱漂亮的女人们一起来逛这个集市' );
		
		// 加载js文件
		$this->set ( 'scriptList', array (
				'index.js' 
		) );
		
		// 加载css文件
		$this->set ( 'cssList', array (
				'index.css' 
		) );
		
		$this->loadModel ( 'Goods' );
		
		// 接收分页参数
		if (isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] )) {
			if (floor ( $this->params ['page'] ) < 1) {
				$curpage = 1;
			} else {
				$curpage = floor ( $this->params ['page'] );
			}
		} else {
			$curpage = 1;
		}
		
		// limit
		$limit = ($curpage - 1) * $this->perpage . ', ' . $this->perpage;
		
		// 整理搜索条件
		$conditions = array ();
		
		$list = $this->Goods->GetGoodsByList ( $conditions, $limit );
		if ($list) {
			foreach ( $list ['result'] as &$val ) {
				if (! empty ( $val ['Goods'] ['price'] )) {
					$price_arr = explode ( '.', $val ['Goods'] ['price'] );
					$val ['Goods'] ['price_block'] = $price_arr [0];
					$val ['Goods'] ['price_points'] = $price_arr [1];
				}
			}
		}
		
		$this->set ( 'list', $list ['result'] );
		// 分页参数
		$this->set ( 'total', $list ['count'] );
		$this->set ( 'perpage', $this->perpage );
		$this->set ( 'curpage', $curpage );
	}
}
?>